package com.devunion.reader.client.command;

import com.devunion.reader.client.core.AsyncCommand;
import com.devunion.reader.client.to.UserManagementTo;
import com.devunion.reader.client.service.UserService;
import com.extjs.gxt.ui.client.data.DataProxy;
import com.extjs.gxt.ui.client.data.DataReader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.ListLoadConfig;
import com.google.gwt.user.client.rpc.AsyncCallback;

import java.util.List;

/**
 * @author Aliaksandr Tsimashenka 16.03.2010 : 19:41:02
 */
public class UserManagementCmd extends AsyncCommand<ListLoadResult<UserManagementTo>>
        implements DataProxy<ListLoadConfig, ListLoadResult<UserManagementTo>> {
    private AsyncCallback<ListLoadResult<UserManagementTo>> listLoadResultAsyncCallback;

    public void attempt() {
        UserService.App.getInstance().getUsers(this);
    }

    public void oncapture(ListLoadResult<UserManagementTo> value) {
        this.listLoadResultAsyncCallback.onSuccess(value);
    }

    public void load(DataReader<ListLoadConfig, ListLoadResult<UserManagementTo>> listLoadConfigListLoadResultDataReader,
                     ListLoadConfig listLoadConfig, AsyncCallback<ListLoadResult<UserManagementTo>> listLoadResultAsyncCallback) {
        this.listLoadResultAsyncCallback = listLoadResultAsyncCallback;

        attempt();
    }
}
